// pages/detail/detail.js
const app = getApp();
import api from '../../utils/api.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showLogin:false,
    whiceOnOff: null,
    examItem: {},
    online_price: null,
    offline_price: null,
    isOnline: true,
    isOffline: true
  },
  
  // 放大图片
  enlargeImg(e){
    let API_URL = 'https://api.lailiaosheji.com/'
    // let exam_content = URL + this.data.examItem.exam_content
    // let treaty_content = URL + this.data.examItem.treaty_content
    // let imgUrlArr = [exam_content, treaty_content]
    wx.previewImage({
      urls: [API_URL + e.currentTarget.dataset.img],
      success(res){
        console.log(res)
      }
    })
  },
  showModal(e){
    
    if(e.currentTarget.id === 'offline'){
      this.setData({
        whiceOnOff: 'offline'
      })
    }else if(e.currentTarget.id === 'online'){
      this.setData({
        whiceOnOff: 'online'
      })
    }
    this.setData({
      showLogin: true
    })
  },
  handleCancel(){
    this.setData({
      showLogin: false
    })
  },
  handleConfirm(e){
    if(this.data.whiceOnOff === 'offline'){
      wx.navigateTo({
        url: '/pages/offlinePay/offlinePay',
      })
    } else if (this.data.whiceOnOff === 'online'){
      wx.navigateTo({
        url: '/pages/onlinePay/onlinePay',
      })
    }
    this.setData({
      showLogin: false
    })
  },
  // goToOffLine(e){
  //   wx.showModal({
  //     content: '确定已阅读并同意协议吗？',
  //     cancelText: '不同意',
  //     confirmText: '确定',
  //     confirmColor: '#fff'
  //   })
  // },

  getDetail(){
    let obj = {
      exam_id: app.globalData.examItem.exam_id
    }
    api.POST('/applet/exam/detail', obj, res => {
      console.log(res)
      this.setData({
        online_price: res.data.online_price,
        offline_price: res.data.offline_price,
      })
      if (res.data.exam_status === 1){
        this.setData({
          isOnline: false
        })
      }
      if (res.data.exam_status === 2){
        this.setData({
          isOffline: false
        })
      }
      if (res.data.exam_status === 3){
        this.setData({
          isOffline: false,
          isOnline: false
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDetail()
    this.setData({
      examItem: app.globalData.examItem
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})